package cn.iocoder.yudao.module.infra.controller.admin.face;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.infra.controller.admin.face.vo.FaceLogPageReqVO;
import cn.iocoder.yudao.module.infra.controller.admin.face.vo.FaceLogRespVO;
import cn.iocoder.yudao.module.infra.convert.face.FaceLogConvert;
import cn.iocoder.yudao.module.infra.dal.dataobject.face.FaceLogDO;
import cn.iocoder.yudao.module.infra.service.face.FaceLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

/**
 * 管理后台 - 人脸验证日志
 *
 * @author 芋道源码
 */
@Tag(name = "管理后台 - 人脸验证日志")
@RestController
@RequestMapping("/infra/face-log")
@Validated
@Slf4j
public class FaceLogController {

    @Resource
    private FaceLogService faceLogService;

    @GetMapping("/page")
    @Operation(summary = "获得人脸验证日志分页")
    @PreAuthorize("@ss.hasPermission('infra:face-log:query')")
    public CommonResult<PageResult<FaceLogRespVO>> getLogPage(@Valid FaceLogPageReqVO pageReqVO) {
        PageResult<FaceLogDO> pageResult = faceLogService.getLogPage(pageReqVO.getPageNo(), pageReqVO.getPageSize(),
                pageReqVO.getUserId(), pageReqVO.getOperationType(), pageReqVO.getSuccess());
        return success(FaceLogConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/get")
    @Operation(summary = "获得人脸验证日志")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('infra:face-log:query')")
    public CommonResult<FaceLogRespVO> getLog(@RequestParam("id") @NotNull Long id) {
        FaceLogDO faceLog = faceLogService.getLog(id);
        return success(FaceLogConvert.INSTANCE.convert(faceLog));
    }

}